package cn.itcast.nems.product.scheduler;

import cn.itcast.nems.product.dao.dataobject.ProductDO;
import cn.itcast.nems.product.service.ProductService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author liyong
 * create: 2023-09-06 16:02:43
 **/
public class PriceChangeProductProcessor {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    private final int successCount;
    private final List<ProductDO> result;

    public PriceChangeProductProcessor(ProductService productService,
                                       BaseDataProcessor baseDataProcessor,
                                       List<ProductDO> products,
                                       String operator) {
        PriceChangeProductCal priceChangeProductCal = new PriceChangeProductCal(products,
                baseDataProcessor.getTuitionFees(),
                baseDataProcessor.getPhases(),
                baseDataProcessor.getSchools());
        this.result = priceChangeProductCal.calculate();
        logger.info("需要更新当天价格的产品数 {} ", result.size());
        this.successCount = productService.updateProductStates(result, operator);
    }

    public int getSuccessCount() {
        return successCount;
    }

    public int getProcessCount() {
        return this.result != null ? this.result.size() : 0;
    }

    public List<ProductDO> getResult() {
        return result;
    }
}
